/*
 * test_casinfo.cpp
 *
 *  Created on: 2016年3月14日
 *      Author: guyadong
 */
#include <iostream>
#include <sstream>
#include "casinfo.h"
using namespace gdface;
using namespace std;
void compare_feathers(const feather_cl*f1, const feather_cl*f2,size_t size) {
	for (size_t i = 0; i < size; ++i) {
		if (f1[i] != f2[i]) {
			cout << i << "not equal" << endl;
			cout.precision(10);
			cout << "f[" << i << "]=" << f1[i].DValve << " cas.Feather=[" << f2[i].DValve << "]" << std::endl;

		}
	}
}
int main(int argc, char * argv[]){
	try{
		const size_t img_size=4096;
		/*
		auto scale_sizes=detect_face::get_scale_level(img_size, DETECT_WIN_SIZE,0.7f,0.0f,0.8f);
		//auto scale_sizes = detect_face::get_scale_level(2048, DETECT_WIN_SIZE, size_t(400), size_t(40), 0.8f);
		for(size_t i=0;i<scale_sizes.size();++i){
			std::cout<<i<<":\t" << size_t(scale_sizes[i] * img_size) << "\t" <<scale_sizes[i]<<std::endl;
		}*/
		//auto scale_sizes = detect_face::get_detect_win_size_level(img_size, DETECT_WIN_SIZE, 1.0f, 0.0f, 1.1f);
		/*auto scale_sizes = detect_face::get_detect_win_size_level(img_size, DETECT_WIN_SIZE, img_size, DETECT_WIN_SIZE, 1.1f);
		for (size_t i = 0; i<scale_sizes.size(); ++i) {
			std::cout << i << ":\t" << size_t(scale_sizes[i]) << std::endl;
		}*/
		auto cas=load_casinfo_file("CascadeInfo",SCALE_SIZE);
		auto cas_m=cas;
		cas_m.build_feathers(global_measure);
		auto f=cas_m.Feather;
		//auto f=magnify_feathers_from0(cas.Feather.data(),cas.FeatherNumPerCas,SCALE_SIZE,SCALE);		
		compare_feathers(f.data(), cas.Feather.data(), f.size());
		save_casinfo_json_file(cas,"d:\\tmp\\cascadeinfo_json.txt");
		std::basic_ostringstream<char> stream;
		save_casinfo_json(cas,dynamic_cast<std::ostream&>(stream));
		std::string json_str = stream.str();
		auto base64=casinfo_to_json_str(cas,false,true,true);
		save_binary_file("d:\\tmp\\cascadeinfo_json_compressed_base64.txt", (const uint8_t*)base64.data(),base64.size());
		auto cas2=load_casinfo_json_compressed_base64(base64);
		auto cas_from_json=load_casinfo_json(json_str);
	}
	catch (std::exception &e) {
		std::cout << e.what() << std::endl;
	}
}


